package com.longer.demo.framework.privilege;

import com.longer.demo.biz.domain.UserDO;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpSession;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @program: demo
 * @description:
 * @author: SunBiaoLong
 * @create: 2019-01-07 19:32
 **/
@Component
public class UserSession {
	private static Map<String , UserDO> userMap=new ConcurrentHashMap<>();
	public void saveUser(HttpSession session,UserDO userInfo){
		String id = session.getId();
		if (userMap.get(id)!=null){
			//@TODO
			//用户已经登录
		}else {
			//保存用户
			//@TODO 如果出现重复登录怎么办
			userMap.put(id, userInfo);
		}
	}

	public UserDO getUser(HttpSession session){
		UserDO user = userMap.get(session.getId());
		if (user!=null){
			return user;
		}else {
			return null;
		}
	}

}
